﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using GA.Server.ApiInfo;
using System.Xml;

namespace GA.Server.Api
{
    public class ApiInfoGetAllianceInfo : SignedApiCall
    {
        public IEnumerable<ApiAgency> Agencies { get; private set; }

        public ApiInfoGetAllianceInfo()
        {
        }

        public ApiInfoGetAllianceInfo(int clientId, string authorizationText, string sessionId)
            : base(clientId, authorizationText, sessionId)
        {
        }

        public void LoadApi(int allianceId)
        {
            LoadSignedApiCall(string.Format("allianceId={0}", allianceId));

            XmlNodeList agencyNodes = XmlDocument.GetElementsByTagName("a:stats_get_allianceResult");
            List<ApiAgency> agencies = new List<ApiAgency>();
            foreach (XmlNode agencyNode in agencyNodes)
            {
                agencies.Add(new ApiAgency(agencyNode.CreateNavigator().ReadSubtree()));
            }
            Agencies = agencies;
        }

        protected override string ApiCallName
        {
            get { return "GetAllianceInfo"; }
        }
    }
}
